<?php

namespace app\product\controller;
use app\common\controller\PCBase;
use app\common\controller\DBase;
use app\product\logic\ProductLogic;
use think\App;
use app\common\library\Upload;

class ProductEstimate extends DBase
{

    protected $productLogic = null;
    public function __construct(App $app,ProductLogic $productLogic)
    {
        parent::__construct($app);
        $this->productLogic = $productLogic;
    }

    /**
     * @desc  产品订单预估值计算
     * @date  2024/4/20
     * @author  luckyXiong
     */
    public function index(){
        $params     = $this->request->post();
        return $this->productLogic->getProductFeeList($params);
    }


    /**
     * 编辑数据
     * @throws Throwable
     */
    public function edit($id='')
    {

        $row = $this->productLogic->get_row($id);
        if (!$row) {
            return json(DefaultResponse(201, false, '记录不能为空!', null));
        }
        if ($this->request->isPost()) {
            $data = $this->request->post();
            return $this->productLogic->editOrderFinancial($data);
        }
        return json(DefaultResponse(200, true, '获取成功', ['row' => $row]));
    }



    /**
     * 编辑数据
     * @throws Throwable
     */
    public function updateCost(){
        $params     = $this->request->post();
        return $this->productLogic->updateCost($params);
    }



    /**
     * @模版下载
     * @throws Throwable
     */
    public function getExportInfo()
    {
        $params   = $this->request->get();
        return $this->productLogic->getExportInfo($params);
    }


    /**
     * @上传数据
     * @throws Throwable
     */
    public function getUploadInfo()
    {
        $file       = $this->request->file('file');
        $upload     = new Upload($file);
        $attachment = $upload->upload(null, 1);
        $this->productLogic->getUploadInfo($attachment['url']);
        return  $this->jsonMessage(200, true, "上传成功!",null);
    }





}